<?php
class ControlPanel {
    var $default_settings;
    
    var $options;
    
	function ControlPanel() {

		add_action('admin_menu', array(&$this, 'add_menu'));
        add_action('admin_head', array(&$this, 'admin_head')); 

        if (!is_array(get_option('po_theme')))
            add_option('po_theme', $this->default_settings);
        
        $this->options = get_option('po_theme');
	}

    function add_menu() {
        add_object_page('Panda Theme - Settings', 'Theme&nbsp;Settings', 'edit_themes', "po_theme", array(&$this, 'options_menu'));
    }

    function admin_head() {
        echo '<link rel="stylesheet" href="'.get_bloginfo('template_url').'/admin/admin.css" type="text/css" media="screen" />
    		  <link rel="stylesheet" media="screen" type="text/css" href="'.get_bloginfo('template_url').'/admin/js/colorpicker/css/colorpicker.css" />';
		
		if ($_GET['page'] == "po_theme") {
			echo '<script type="text/javascript" src="'.get_bloginfo('template_url').'/assets/js/lib/jquery.js"></script>
			<script type="text/javascript" src="'.get_bloginfo('template_url').'/admin/js/colorpicker/js/colorpicker.js"></script>
			<script type="text/javascript" src="'.get_bloginfo('template_url').'/admin/js/admin.js"></script>
			';
		}
	}
	
	function options_menu() {
		
		$current_themestyle = $this->options["themestyle"];
        if ($_POST['po_action'] == 'save') {
//	    <!----------------------------------------------------------------------------
//									A D M I N  T A B S
//		----------------------------------------------------------------------------->
			if (!$_POST['tab']) { $this->options["tab"] = 0; } else { $this->options["tab"] = $_POST['tab']; }

//	    <!----------------------------------------------------------------------------
//									G E N E R A L
//		----------------------------------------------------------------------------->
			if (!$_POST['logo']) { $this->options["logo"] = get_bloginfo('template_url')."/images/logo.png"; } else { $this->options["logo"] = $_POST['logo']; }	
			$this->options["logo_type"] = $_POST['logo_type'];
			if (!$_POST['favicon']) { $this->options["favicon"] = get_bloginfo('template_url')."/favicon.ico"; } else { $this->options["favicon"] = $_POST['favicon']; }
			$this->options["google_analytics"] = stripslashes($_POST['google_analytics']);
			$this->options["copyrights"] = stripslashes($_POST['copyrights']);
			$this->options["panda_link_display"] = $_POST['panda_link_display'];

//	    <!----------------------------------------------------------------------------
//									H O M E P A G E
//		----------------------------------------------------------------------------->
//			THUMBS
			$this->options["thumbs_source"] = stripslashes($_POST['thumbs_source']);
			$this->options["featured_cat"] = $_POST['featured_cat'];
			$this->options["featured_flickr_source_type"] = $_POST['featured_flickr_source_type'];
			$this->options["flickr_target"] = $_POST['flickr_target'];
			if (!stripslashes($_POST['featured_flickr'])) { $this->options["featured_flickr"] = "10729228@N07"; } else { $this->options["featured_flickr"] = stripslashes($_POST['featured_flickr']); }
			if (!$_POST['featured_qty']) { $this->options["featured_qty"] = "10"; } else { $this->options["featured_qty"] = $_POST['featured_qty']; }
			$this->options["featured_sort"] = $_POST['featured_sort'];
			$this->options["featured_thumbs_size"] = $_POST['featured_thumbs_size'];
			$this->options["featured_thumbs_rotation"] = $_POST['featured_thumbs_rotation'];
			$this->options["frontpage"] = $_POST['frontpage'];

//	    <!----------------------------------------------------------------------------
//									P O R T F O L I O
//		----------------------------------------------------------------------------->
			$this->options["enable_portfolio"] = stripslashes($_POST['enable_portfolio']);
			$this->options["portfolio_cat"] = $_POST['portfolio_cat'];
			$this->options["portfolio_posts_template"] = $_POST['portfolio_posts_template'];

//	    <!----------------------------------------------------------------------------
//									M I S C
//		----------------------------------------------------------------------------->
//			TEMPLATES
			$this->options["entries_template"] = $_POST['entries_template'];

//			LIFESTREAM
			$this->options["enable_lifestream"] = stripslashes($_POST['enable_lifestream']);
			$this->options["life_rss"] = stripslashes($_POST['life_rss']);
			$this->options["life_twitter"] = stripslashes($_POST['life_twitter']);
			$this->options["life_deviantart"] = stripslashes($_POST['life_deviantart']);
			$this->options["life_digg"] = stripslashes($_POST['life_digg']);
			$this->options["life_facebook"] = stripslashes($_POST['life_facebook']);
			$this->options["life_flickr"] = stripslashes($_POST['life_flickr']);
			$this->options["life_lastfm"] = stripslashes($_POST['life_lastfm']);
			$this->options["life_linkedin"] = stripslashes($_POST['life_linkedin']);
			$this->options["life_myspace"] = stripslashes($_POST['life_myspace']);
			$this->options["life_picasa"] = stripslashes($_POST['life_picasa']);
			$this->options["life_reddit"] = stripslashes($_POST['life_reddit']);
			$this->options["life_skype"] = stripslashes($_POST['life_skype']);
			$this->options["life_stumbleupon"] = stripslashes($_POST['life_stumbleupon']);
			$this->options["life_technorati"] = stripslashes($_POST['life_technorati']);
			$this->options["life_youtube"] = stripslashes($_POST['life_youtube']);
			$this->options["life_vimeo"] = stripslashes($_POST['life_vimeo']);
			$this->options["life_blogger"] = stripslashes($_POST['life_blogger']);
			$this->options["life_delicious"] = stripslashes($_POST['life_delicious']);
			$this->options["life_designfloat"] = stripslashes($_POST['life_designfloat']);
			$this->options["life_designmoo"] = stripslashes($_POST['life_designmoo']);

//			SIDEBARS
			$this->options["enable_footersidebars"] = stripslashes($_POST['enable_footersidebars']);
			$this->options["additional_sidebars"] = stripslashes($_POST['additional_sidebars']);

//			MISC
			$this->options["enable_author_info"] = stripslashes($_POST['enable_author_info']);

//	    <!----------------------------------------------------------------------------
//									C U S T O M  S T Y L E
//		----------------------------------------------------------------------------->
//			BASIC STYLE
			$this->options["style"] = $_POST['style'];

//			BODY
			$this->options["background_color"] = $_POST['background_color'];
			$this->options["pattenr"] = $_POST['pattenr'];
			$this->options["background_image"] = $_POST['background_image'];
			$this->options["background_image_position"] = $_POST['background_image_position'];
			$this->options["background_repeat"] = $_POST['background_repeat'];

//			MENU
			$this->options["menu_color"] = $_POST['menu_color'];
			$this->options["menu_bg_color"] = $_POST['menu_bg_color'];
			$this->options["menu_hover_color"] = $_POST['menu_hover_color'];
			$this->options["menu_hover_bg_color"] = $_POST['menu_hover_bg_color'];
			$this->options["menu_selected_color"] = $_POST['menu_selected_color'];
			$this->options["menu_selected_bg_color"] = $_POST['menu_selected_bg_color'];

//			TITLES
			$this->options["h1_color"] = $_POST['h1_color'];
			$this->options["titles_color"] = $_POST['titles_color'];
			$this->options["titles_font"] = $_POST['titles_font'];
			$this->options["titles_font_weight"] = $_POST['titles_font_weight'];

//			CONTENT
			$this->options["font"] = $_POST['font'];
			$this->options["links_color"] = $_POST['links_color'];
			$this->options["links_hover_color"] = $_POST['links_hover_color'];
			$this->options["border_color"] = $_POST['border_color'];

//			CUSTOM CSS
			$this->options["custom_css"] = stripslashes($_POST['custom_css']);

//	    <!----------------------------------------------------------------------------
//									A D S
//		----------------------------------------------------------------------------->
//			ADS 300x250
			$this->options["adsense300"] = stripslashes($_POST['adsense300']);
			if (!$_POST['image300']) { $this->options["image300"] = get_bloginfo('template_url')."/images/temp/300x250a.jpg"; } else { $this->options["image300"] = $_POST['image300']; }
			if (!$_POST['target300']) { $this->options["target300"] = "http://pandathemes.com/"; } else { $this->options["target300"] = $_POST['target300']; }

//			ADS 125x125
			if (!$_POST['image125_1']) { $this->options["image125_1"] = get_bloginfo('template_url')."/images/temp/125x125a.png"; } else { $this->options["image125_1"] = $_POST['image125_1']; }
			if (!$_POST['target125_1']) { $this->options["target125_1"] = "http://pandathemes.com/"; } else { $this->options["target125_1"] = $_POST['target125_1']; }
			$this->options["ads125_1"] = $_POST['ads125_1'];

			if (!$_POST['image125_2']) { $this->options["image125_2"] = get_bloginfo('template_url')."/images/temp/125x125a.png"; } else { $this->options["image125_2"] = $_POST['image125_2']; }
			if (!$_POST['target125_2']) { $this->options["target125_2"] = "http://pandathemes.com/"; } else { $this->options["target125_2"] = $_POST['target125_2']; }
			$this->options["ads125_2"] = $_POST['ads125_2'];

			if (!$_POST['image125_3']) { $this->options["image125_3"] = get_bloginfo('template_url')."/images/temp/125x125a.png"; } else { $this->options["image125_3"] = $_POST['image125_3']; }
			if (!$_POST['target125_3']) { $this->options["target125_3"] = "http://pandathemes.com/"; } else { $this->options["target125_3"] = $_POST['target125_3']; }
			$this->options["ads125_3"] = $_POST['ads125_3'];

			if (!$_POST['image125_4']) { $this->options["image125_4"] = get_bloginfo('template_url')."/images/temp/125x125a.png"; } else { $this->options["image125_4"] = $_POST['image125_4']; }
			if (!$_POST['target125_4']) { $this->options["target125_4"] = "http://pandathemes.com/"; } else { $this->options["target125_4"] = $_POST['target125_4']; }
			$this->options["ads125_4"] = $_POST['ads125_4'];

			if (!$_POST['image125_5']) { $this->options["image125_5"] = get_bloginfo('template_url')."/images/temp/125x125a.png"; } else { $this->options["image125_5"] = $_POST['image125_5']; }
			if (!$_POST['target125_5']) { $this->options["target125_5"] = "http://pandathemes.com/"; } else { $this->options["target125_5"] = $_POST['target125_5']; }
			$this->options["ads125_5"] = $_POST['ads125_5'];

			if (!$_POST['image125_6']) { $this->options["image125_6"] = get_bloginfo('template_url')."/images/temp/125x125a.png"; } else { $this->options["image125_6"] = $_POST['image125_6']; }
			if (!$_POST['target125_6']) { $this->options["target125_6"] = "http://pandathemes.com/"; } else { $this->options["target125_6"] = $_POST['target125_6']; }
			$this->options["ads125_6"] = $_POST['ads125_6'];

        	update_option('po_theme', $this->options);
            echo '<div class="updated fade" id="message" style="background-color: rgb(255, 251, 204);"><p>Your settings have been saved.</p></div>';
        }
		include('includes/admin_form.php');
	}
}
?>